//
//  newsestDetailWebViewController.m
//  A Learning Walk
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 战斗民族. All rights reserved.
//

#import "newsestDetailWebViewController.h"
@interface newsestDetailWebViewController ()<UIWebViewDelegate>

@end

@implementation newsestDetailWebViewController



- (void)webViewDidFinishLoad:(UIWebView *)webView {
    self.navigationItem.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //加载H5网页
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    webView.scalesPageToFit = YES;
    webView.delegate = self;
    [webView setOpaque:NO];//opaque是不透明的意思
    [webView setScalesPageToFit:YES];//自动缩放以适应屏幕

   //NSLog(@"%@",self.type);
    if ([self.type isEqualToString:@"3"]) {
        NSLog(@"%@",self.ID);
        NSString *string = [NSString stringWithFormat:@"http://v.autohome.com.cn/v_4_%@.html",self.ID];
        NSURL *url = [NSURL URLWithString:string];
        NSURLRequest* request = [NSURLRequest requestWithURL:url];//创建NSURLRequest
        [webView loadRequest:request];//加载
    }else{
        NSString *string = [NSString stringWithFormat:@"http://cont.app.autohome.com.cn/autov4.2.5/content/News/newscontent-a2-pm1-v4.2.5-n%@-lz0-sp0-nt0-sa1-p0-c1-fs0-cw320.html",self.ID];
        NSURL *url = [NSURL URLWithString:string];
        NSURLRequest* request = [NSURLRequest requestWithURL:url];//创建NSURLRequest
        [webView loadRequest:request];//加载
    }
 
    [self.view addSubview:webView];
    [webView release];
    
//    //横竖屏切换
//    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
//    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
    
    //左按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(leftAction)];
    //右按钮们
    UIBarButtonItem *itemOne = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"np_like_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(itemOneAction:)];
    UIBarButtonItem *itemTwo = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(itemTwoAction:)];
    self.navigationItem.rightBarButtonItems = @[itemTwo, itemOne];
    
}


-(void)itemTwoAction:(UIBarButtonItem *)item{
    NSLog(@"21");

}
-(void)itemOneAction:(UIBarButtonItem *)item{
    NSLog(@"12");

}




-(void)leftAction{
    [self.navigationController popViewControllerAnimated:YES];
}


@end
